﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace DScheme.DancerClasses
{
    class DancerActionRotateTo : DancerActionRotateOn
    {
        double destAngle;
        bool roteteByShortWay = false;

        public DancerActionRotateTo(Dancer dancer, double destAngle, double startTime, double moveTime, bool roteteByShortWay)
            : base(dancer, 0, startTime, moveTime)
        {
            if (roteteByShortWay && (destAngle >= 360 || destAngle < 0)) throw new Exception("Целевой угол находится вне границ диапазона. Для режима поворота по короткому пути, целевой угол должен быть в пределах от 0 до 359.(9)");
            this.destAngle = destAngle;
            this.roteteByShortWay = roteteByShortWay;
        }

        protected override void ExecuteBeforeStart()
        {
            base.ExecuteBeforeStart();
            if (roteteByShortWay)
            {
                double startAngleNormalized = DancerMover.NormalizeAngle(startAngle);
                moveAngle = destAngle - startAngleNormalized;
                if (moveAngle > 180) moveAngle -= 360;
                if (moveAngle <= -180) moveAngle += 360;
                return;
            }
            else
            {
                moveAngle = destAngle - startAngle;
            }
        }
    }

    class DancerActionRotateOn : DancerAction
    {
        protected double startAngle;
        protected double moveAngle;

        public DancerActionRotateOn(Dancer dancer, double moveAngle, double startTime, double moveTime)
            : base(dancer, startTime, moveTime)
        {
            this.moveAngle = moveAngle;
        }

        protected override void ExecuteBeforeStart()
        {
            startAngle = dancer.Angle;
        }

        protected override void ExecuteAction(double actTimeS)
        {
            dancer.Angle = startAngle + moveAngle * DoneValue;
        }

        protected override void ExecuteDone()
        {
            dancer.Angle = startAngle + moveAngle;
        }

    }

}
